<div class="category_tree">
    <?php 
        $previous_depth = null;

        // Open up the categories list
        echo '<ul>';

        $escaper = new Zend\Escaper\Escaper('utf-8');
        
        for ($i = 0; $i < count($this->categories); $i += 3) {
            $depth = str_word_count($this->categories[$i]->getPath(), null, '.');

            // Add a cosmetic rule between two categories at different depths
            if ($previous_depth != null && $previous_depth < $depth)
            	echo '<li><hr></li>';

            if ($previous_depth != null && $previous_depth > $depth)
            	echo '<li><div class="separator"></div></li>';
            
            // Add a category
            echo '<li class="category_'.$depth.'"><a href="'.$this->url('catalog/category', 
                array('controller' => 'category', 'action' => 'list', 'category_alias' => $this->categories[$i + 2]->getText(), 'page' => 1), array(), true).'">'.$escaper->escapeHtml($this->categories[$i + 1]->getText()).'</a></li>';
            
            $previous_depth = $depth;
        }
        
        // Close the categories list
        echo '</ul>';
    ?>
</div>